package com.zhida.smartcontrol.pagectrl.devicedetail.holiday;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.jay.tools.recycler.MultipleViewHolder;
import com.jay.tools.recycler.SingleRecyclerAdapter;
import com.zhida.smartcontrol.R;

import java.util.List;

public class HolidayAdapter extends SingleRecyclerAdapter<HolidayBean> {

    public HolidayAdapter(@Nullable List<HolidayBean> data) {
        super(R.layout.item_auto_time, data);
    }

    @Override
    protected void convert(MultipleViewHolder holder, HolidayBean info) {
        TextView tvName = holder.getView(R.id.tv_tt);
        TextView tvFirst = holder.getView(R.id.tv_first);
        TextView tvSecond = holder.getView(R.id.tv_second);
        TextView tvThird = holder.getView(R.id.tv_third);
        View view1 = holder.getView(R.id.ll_sd_1);
        View view2 = holder.getView(R.id.ll_sd_2);
        View view3 = holder.getView(R.id.ll_sd_3);

        tvName.setText(info.getName());

        setData(info.getFirstStartTime(), info.getFirstEndTime(), view1, tvFirst);
        setData(info.getSecondStartTime(), info.getSecondEndTime(), view2, tvSecond);
        setData(info.getThirdStartTime(), info.getThirdEndTime(), view3, tvThird);
    }

    private void setData(String time1, String time2, View view, TextView tv) {
        if (TextUtils.isEmpty(time1) && TextUtils.isEmpty(time2)) {
            view.setVisibility(View.GONE);
        } else {
            view.setVisibility(View.VISIBLE);
            tv.setText(time1 + "-" + time2);
        }
    }

}
